package thread;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 钟表
 */
public class ThreadDemo04 {
    public static void main(String[] args) {
        Callable<Integer> callable = new Callable() {
            @Override
            public Integer call() throws Exception {
                System.out.println("callable 执行了~~~");
                return 123;
            }
        };
        FutureTask<Integer> futureTask = new FutureTask<Integer>(callable);
        Thread thread = new Thread(futureTask);
        thread.start();
        try {
           int num =  futureTask.get();
            System.out.println(num);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }


        SimpleDateFormat sdf = new SimpleDateFormat(" HH:mm:ss");
        while (true){
            Date time = new Date();
            System.out.println(sdf.format(time));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }


    }
}
